import { createStore } from 'vuex'
import {getLyric} from "@/utils/api.js"
export default createStore({
  state: {
    playList: [{
      al: {
        id: 143139140,
        name: "Phase one",
        pic: 109951167257577060,
        picUrl: "https://p1.music.126.net/-vCqiLu7SO29RNMVLun7Bg==/109951167257577057.jpg",
        pic_str: "109951167257577057"
      },
      id: 1935967544,
      name: "Phase one"
    }],
    playListIndex:0,
    isPlaying:false,
    isDetailShow:false,
    currentLyric:{},
    currentPlayTime:0,
    isLogin:false,
    isFooterShow:true,
    userId:""
  },
  mutations: {
    changePlaying:function(state,value){
      
      state.isPlaying=!state.isPlaying
      console.log("改变了",state.isPlaying)
    },
    changePlayList:function(state,value){
      state.playList=value
    },
    changePlaySong:function(state,value){
      console.log(state.playList)
      console.log(value)
      if(state.playListIndex!==0&&state.playListIndex!=state.playList.length-1){
        console.log("diyibu")
        state.playListIndex=state.playListIndex+value
      }
      else if(state.playListIndex==0){
        console.log(state.playList.length)
        if(value==-1){
          state.playListIndex=state.playList.length-1
        }else{
          state.playListIndex=state.playListIndex+value
        }
      }
      else{
        console.log("disanbu")
        if(value==-1){
          state.playListIndex=state.playListIndex+value
        }else{
          state.playListIndex=0
        }
      }
    
    },
    changePlayingSong:function(state,value){
      state.playListIndex=value
      state.isPlaying=true
    },
    changeDetailShow:function(state,value){
      state.isDetailShow=!state.isDetailShow
    },
    changeCurrentLyric:function(state,value){
      state.currentLyric=value
    },
    changePlayTime:function(state,value){
      state.currentPlayTime=value
    },
    changeAddPlay:function(state,value){
      state.playList.unshift(value)
      // state.playListIndex=0
     
    },
    changeLogin:function(state,value){
      state.isLogin=value
    },
    changeFooterShow: function(state,value){
      state.isFooterShow=value
    },
    changeUserId:function(state,value){
      state.userId=value
    }

  },
  actions: {
    getCurrentLyric: async function(context,value){
      const response=await getLyric(value)
      console.log(response)
      context.commit("changeCurrentLyric",response.data.lrc)
    }
  },
  modules: {
  }
})
